<?php

namespace Controller;

//Controller för nytt inlägg
class NewObjectController {
	/**
	 * @return String $xhtml
	 */

		public function DoControll($database) {
		$xhtml = "";
		$messageid = 0;
		$message = "";

		$objectView = new \View\ObjectView();
		$ph = new \Model\ObjectHandler($database);
		$lv = new \View\LoginView();
		if ($objectView -> TriedToSubmit()) {
			$messageid = $ph -> newObject($_COOKIE['userID'], $objectView->CatID(), $objectView ->Title(), $objectView -> Content(), $objectView -> Price());

			if ($messageid == \Model\ObjectHandler::OBJECT_EMPTY) {
				$message .= $objectView -> NewPostMess(\View\ObjectView::OBJECT_EMPTY);
			}
			if ($messageid == \Model\ObjectHandler::OBJECT_SUCCESS) {
				$message .= $objectView -> NewPostMess(\View\ObjectView::OBJECT_SUCCESS);

			}
			if ($messageid == \Model\ObjectHandler::OBJECT_FAILED) {
				$message .= $objectView -> NewPostMess(\View\ObjectView::OBJECT_FAILED);
			}
		}

		$xhtml .= $message;
		$xhtml .= $objectView -> NewobjectForm();

		return $xhtml;
	}

}
